<script lang="ts" setup>
import { useRouter, useRoute } from "vue-router";
import { ref } from "vue"
import type { BLEData } from "../../const/BLEconst";
import { blestore } from "../../store/ble"
import { cancelBluetoothRequest,bluetoothPairingRequest,bluetoothPairingResponse } from "../../util/BLEUtils"
const bleStore = blestore()
const bleList: Array<BLEData> = bleStore.bleList
const router = useRouter()

const route = useRoute();

const handleClick = ({ row, column, $index }) => {
  console.log(row)
  console.log(column)
  console.log($index)
  bleStore.isConnectBLE = true
  bleStore.putBleData(row)
  console.log(route?.query)
  const redirectUrl = route?.query?.redirect;

  let redirectUrlStr = ''
  if (redirectUrl) {
    redirectUrlStr = redirectUrl.toString();
  }
  console.log(redirectUrlStr)
  if (redirectUrlStr) {
    router.push({
      path: redirectUrlStr
    })

  } else {
    router.push({ path: "/" })
  }
}
</script>

<template>
  <el-table :data="bleList" stripe style="width: 100%">
    <el-table-column prop="text" label="蓝牙名称" width="100" />
    <el-table-column prop="value" label="设备id" width="320" />
    <el-table-column prop="操作" label="操作">
      <template #default="{ row, column, $index }">

        <el-button link type="primary" size="small" @click="handleClick({ row, column, $index })"><el-icon>
            <Connection />
          </el-icon>连接设备</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<style lang="scss" scoped></style>